package com.monkey.demolist.preferenceActivity;

import android.content.SharedPreferences;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;

import com.monkey.demolist.R;

public class SettingActivity extends PreferenceActivity {

    private static final String TAG = "SettingActivity";

    public static final String PREFER_NAME = "com.monkey.demolist";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /**
         * 设置版面文件R.xml.perference
         *      addPreferencesFromResource方法在Android3.0中就被弃用了,但却没有替代方法
         *      谷歌的想法是，希望我们继承PreferenceFragment来实现默认选项页,但是这太难了。真的
         */
        getPreferenceManager().setSharedPreferencesName(PREFER_NAME);
        addPreferencesFromResource(R.xml.perference);

        ListPreference myListPreference = (ListPreference) findPreference("myListPreference");
        CheckBoxPreference medf = (CheckBoxPreference) findPreference("medf");
        CheckBoxPreference mlqs = (CheckBoxPreference) findPreference("mlqs");
        EditTextPreference editWord = (EditTextPreference) findPreference("editWord");

        SharedPreferences sp = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
        String myListStr = sp.getString("myListPreference", "你好");
        boolean medfBool = sp.getBoolean("medf", false);
        boolean mlqsBool = sp.getBoolean("mlqs", false);
        String editWordStr = sp.getString("editWord", "你好");


        Log.e(TAG, "onCreate:" + myListStr);
        Log.e(TAG, "onCreate:" + medfBool);
        Log.e(TAG, "onCreate:" + mlqsBool);
        Log.e(TAG, "onCreate:" + editWordStr);
    }
}
